package gupao.concurrency.datasync.controller;

import gupao.concurrency.datasync.task.v1x.*;
import gupao.concurrency.datasync.task.v2.SyncTaskV2;
import gupao.concurrency.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tci/sync")
public class SyncTaskController {

    @Autowired
    private SyncTaskV1Opt syncTaskV1Opt;

    @Autowired
    private SyncTaskV1 syncTaskV1;

    @Autowired
    private SyncTaskV2 syncTaskV2;

    @RequestMapping("/v1/start/{partitions}/{totalNum}")
    public String startV1(@PathVariable int partitions,
                          @PathVariable int totalNum){
        syncTaskV1.syncStart(partitions,totalNum);
        return "startV1. status: " + syncTaskV1.getStatus();
    }

    @RequestMapping("/v1opt/start/{partitions}/{totalNum}")
    public String startV1Opt(@PathVariable int partitions,
                          @PathVariable int totalNum){
        syncTaskV1Opt.syncStart(partitions,totalNum);
        return "startV1. status: " + syncTaskV1Opt.getStatus();
    }

    @RequestMapping("/v2/start/{providerConcurrency}/{apiConcurrency}/{dbConcurrency}/{totalNum}")
    public String startV2(@PathVariable int providerConcurrency,
                          @PathVariable int apiConcurrency,
                          @PathVariable int dbConcurrency,
                          @PathVariable int totalNum){
        syncTaskV2.syncStart(providerConcurrency,apiConcurrency,dbConcurrency, totalNum);
        return JsonUtils.toJsonStr(syncTaskV2.getTaskResult());
    }
}
